#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "rtc6/RTC6impl.hpp"
#include <QMessageBox>
#include <QDebug>

const uint ERROR_NO_ERROR = 0U;
const uint ERROR_NO_CARD = 1U;
const uint ERROR_VERSION_MISMATCH = 256U;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    const auto initDLL = init_rtc6_dll();
    if (initDLL & ERROR_VERSION_MISMATCH)
    {
        qDebug() << "VERSION_MISMATCH";
    }
    else if (initDLL & ERROR_NO_CARD)
    {
        qDebug() << "ERROR_NO_CARD";
    }
    else
    {
        qDebug() << "init failed:" << initDLL;
    }
    if (initDLL != ERROR_NO_ERROR && initDLL != ERROR_NO_CARD)
    {
        QMessageBox::critical(this, "错误", "错误码:" + QString::number(initDLL));
        exit(1);
    }
}

MainWindow::~MainWindow()
{
    free_rtc6_dll();
    delete ui;
}
